var sysId = "";
var nodeId = "";
var nodeName = "";
var tableName = "";
var nodeTypeNew = "";
var isTemplet = "N";
var colDropdownTypeOld; // 定义全局变量，用于选择对话框关闭时恢复主页面数据时使用
var colRuleNameOld; // 定义全局变量，用于选择对话框关闭时恢复主页面数据时使用
var colRuleTitleOld; // 定义全局变量，用于选择对话框关闭时恢复主页面数据时使用
var customPathOld; // 定义全局变量，用于选择对话框关闭时恢复主页面数据时使用
/**
 * 编辑数据
 */
var editTypeIndex = undefined;
var editCodeIndex = undefined;

function endTypeEditing() {
	if (editTypeIndex == undefined) {
		return true;
	}
	if ($('#cbbTabColumnsTypeDataGrid').datagrid('validateRow', editTypeIndex)) {
		$('#cbbTabColumnsTypeDataGrid').datagrid('endEdit', editTypeIndex);
		editTypeIndex = undefined;
		return true;
	} else {
		parent.parent.parent.$.messager.show({
			title :  commonLang.tip.alert,//'提示',
			//commonLang.tip.checkData"请检查数据是否正确！"
			msg : commonLang.tip.checkData,
			timeout : 2000,
			showType : 'slide'
		});
		return false;
	}
}

function endCodeEditing() {
	if (editCodeIndex == undefined) {
		return true;
	}
	if ($('#cbbTabColumnsCodeDataGrid').datagrid('validateRow', editCodeIndex)) {
		$('#cbbTabColumnsCodeDataGrid').datagrid('endEdit', editCodeIndex);
		editCodeIndex = undefined;
		return true;
	} else {
		parent.parent.parent.$.messager.show({
			title : commonLang.tip.alert,//'提示',
			//commonLang.tip.checkData 参数替换"请检查数据是否正确！"
			msg : commonLang.tip.checkData,
			timeout : 2000,
			showType : 'slide'
		});
		return false;
	}
}
/**
 * 子表追加行
 */
function append() {
	if ($('#cbbTabColumnsTypeDataGrid').datagrid("getSelected") != null) {
		var cid = $('#cbbTabColumnsTypeDataGrid').datagrid("getSelected").id; // 主表当前行ID
		var num = $('#cbbTabColumnsCodeDataGrid').datagrid('getRows').length + 1;
		if (endCodeEditing()) {
			$('#cbbTabColumnsCodeDataGrid').datagrid('appendRow', {
				ID : '',
				COLUMN_ID : cid,
				CODE_IS_VALID : 'Y',
				CODE_ORDER : num
			});
			editCodeIndex = $('#cbbTabColumnsCodeDataGrid').datagrid('getRows').length - 1;
			$('#cbbTabColumnsCodeDataGrid')
					.datagrid('selectRow', editCodeIndex).datagrid('beginEdit',
							editCodeIndex);
			changeName(editCodeIndex);
		}
	} else {
		//commonLang.tip.alert '提示',commonLang.tip.operateAfter '请选中字段后，再进行操作！'
		$.messager.alert(commonLang.tip.alert, commonLang.tip.operateAfter, 'warning');
	}
}
/**
 * 显示值给真实值
 * 
 * @param index
 */
function changeName(editIndex) {
	// 定义事件
	var editors = $('#cbbTabColumnsCodeDataGrid').datagrid('getEditors',
			editIndex);
	var sfgzEditor = editors[2];
	var sfgzEditor1 = editors[3];
	sfgzEditor.target.bind('change', function() {
		var value = sfgzEditor.target.val();
		sfgzEditor1.target.val(value);
	});
}
/**
 * 假删除所选的行
 */
function removeit() {
	var rows = $('#cbbTabColumnsCodeDataGrid').datagrid('getChecked');
	if (rows == "") {

		//commonLang.tip.alert '提示',commonLang.tip.content2'请选择要删除的记录！'
		$.messager.alert(commonLang.tip.alert, commonLang.tip.content2, 'warning');
		return;
	}
	$.messager
			.confirm(
					//commonLang.tip.confirm'请确认',commonLang.tip.confirmContent'您确定要删除当前所选的记录？'
					commonLang.tip.confirm,
					commonLang.tip.confirmContent,
					function(b) {
						if (b) {
							// 删除字段
							var deleteData = JSON.stringify(rows);
							$
									.ajax({
										url : 'platform/aos/commtablemanagerController/deleteCbbTabColumnsCodeData.json',
										data : {
											deleteData : deleteData,
											sysId : sysId
										},
										type : 'post',
										dataType : 'json',
										success : function(result) {
											if (result.flag == "failure") {
												parent.parent.parent.$.messager.show({
													title : commonLang.tip.alert,//'提示',
													msg : result.mes
												});
											} else {
												parent.parent.parent.$.messager.show({
													title : commonLang.tip.alert,//'提示',
													//commonLang.optip.success"删除成功！"
													msg : commonLang.optip.success
												});
											}
										}
									});
							for ( var i = 0; i < rows.length; i++) {
								var index = $('#cbbTabColumnsCodeDataGrid')
										.datagrid('getRowIndex', rows[i]);
								$('#cbbTabColumnsCodeDataGrid').datagrid(
										'cancelEdit', index).datagrid(
										'deleteRow', index);
							}
							editIndex = undefined;
						}
					});
}
/**
 * 提交改变的记录
 */
function accept() {
	if (endCodeEditing()) {
		// 校验代码维护表格数据唯一行
		var codeRows = $("#cbbTabColumnsCodeDataGrid").datagrid('getRows');
		var codeNum = JSON.stringify(codeRows.length);
		for ( var i = 0; i < codeNum; i++) {
			var lookupName = codeRows[i].LOOKUP_NAME;
			var lookupCode = codeRows[i].LOOKUP_CODE;
			for ( var j = 0; j < codeNum; j++) {
				var lookupNameTemp = codeRows[j].LOOKUP_NAME;
				var lookupCodeTemp = codeRows[j].LOOKUP_CODE;
				if (i != j) {
					if (lookupName == lookupNameTemp) {
						//commonLang.tip.alert "提示",//commonLang.tip.content3 "第"，commonLang.tip.content20"行【显示值】"，commonLang.tip.content21 不能相同，请查证！", "warning"
						$.messager.alert(commonLang.tip.alert, commonLang.tip.content3 + (i + 1) + commonLang.tip.content20+","
								+ (j + 1) + commonLang.tip.content20+commonLang.tip.content21, "warning");
						return false;
					}
					if (lookupCode == lookupCodeTemp) {
						//commonLang.tip.alert"提示",commonLang.tip.content3 "第"，commonLang.tip.content22"行【真实值】"，commonLang.tip.content21不能相同，请查证！"
						$.messager.alert(commonLang.tip.alert, commonLang.tip.content3 + (i + 1) + commonLang.tip.content22
								+ (j + 1) +commonLang.tip.content22+ commonLang.tip.content21, "warning");
						return false;
					}
				}
			}
		}
		// 新增字段
		var insertRows = $("#cbbTabColumnsCodeDataGrid").datagrid('getChanges',
				'inserted');
		var insertData = JSON.stringify(insertRows);
		// 更新字段
		var selectRow = $('#cbbTabColumnsTypeDataGrid').datagrid('getSelected');
		var index = $('#cbbTabColumnsTypeDataGrid').datagrid('getRowIndex',
				selectRow);
		$('#cbbTabColumnsTypeDataGrid').datagrid('selectRow', index).datagrid(
				'endEdit', index);
		var updateRows = $("#cbbTabColumnsTypeDataGrid").datagrid('getChanges',
				'updated');
		var updateRowsCode = $("#cbbTabColumnsCodeDataGrid").datagrid(
				'getChanges', 'updated');
		var updateData = JSON.stringify(updateRows);
		var updateCodeData = JSON.stringify(updateRowsCode);
		$
				.ajax({
					url : 'platform/aos/commtablemanagerController/saveCbbTabColumnsCodeData.json',
					data : {
						insertData : insertData,
						updateData : updateData,
						updateCodeData : updateCodeData,
						sysId : sysId,
						nodeId : nodeId,
						nodeName : nodeName,
						tableName : tableName
					},
					type : 'post',
					dataType : 'json',
					success : function(result) {
						if (result.flag == "success") {
							parent.parent.parent.$.messager.show({
								title :commonLang.tip.alert,// '提示',
								//commonLang.optip.saveSuccess"保存成功！"
								msg : commonLang.optip.saveSuccess
							});
							var cid = $('#cbbTabColumnsTypeDataGrid').datagrid(
									"getSelected").id;
							reloadDataGridByCid(cid);
							$('#cbbTabColumnsTypeDataGrid').datagrid('reload',
									null);
						} else {
							parent.parent.parent.$.messager.show({
								title : commonLang.tip.alert,//'提示',
								msg : result.mes
							});
							var cid = $('#cbbTabColumnsTypeDataGrid').datagrid(
									"getSelected").id;
							reloadDataGridByCid(cid);
						}
					}
				});
	}
}
/**
 * 转换列类型
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterColType(value, row, index) {
	if (value == 'string') {
		return commonLang.dataType.string;//"字符串";
	} else if (value == 'integer') {
		return commonLang.dataType.integer;//"整型";
	} else if (value == 'date') {
		return commonLang.dataType.date;//"日期时间型";
	}
	return value;
}

/**
 * 转换是否
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterYn(value, row, index) {
	if (value == 'Y') {
		return commonLang.dialog.effective;//"有效";
	} else {
		return commonLang.dialog.invalid;//"无效";
	}
	return value;
}
/**
 * 【下拉类型】转换
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterType(value, row, index) {
	var type = "";
	if (value == '0') {
		type = commonLang.fomaterType.value0;//"无";
	} else if (value == '1') {
		type =commonLang.fomaterType.value1;// "参选";
	} else if (value == '2') {
		type = commonLang.fomaterType.value2;//"只选";
	} else if (value == '3') {
		type = commonLang.fomaterType.value3;//"选择";
	} else if (value == '4') {
		type = commonLang.fomaterType.value4;//"多选";
	}
	if (row.colIsDisplay == "N" && row.colIsSys == "Y") {
		return "<font color='red'>" + type + "</font>";
	} else {
		return type;
	}
}

/**
 * 转换数据类型
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterCtype(value, row, index) {
	if (value == 'S') {
		return commonLang.dialog.system;//"系统";
	} else {
		return commonLang.dialog.buildByOnself;//"自建";
	}
	return value;
}

/**
 * 打开参考模板页面
 */
function openTemplet() {
	var dialogId = "templetFieldDialog";
	var toActionUrl = "platform/aos/commtablemanagerController/toCommTemplet?dialogId="
			+ dialogId
			+ "&sysId="
			+ sysId
			+ "&nodeId="
			+ nodeId
			+ "&nodeName="
			+ nodeName;
	//commonLang.dialog.referenceTemplate "参考模版"
	var usdAdd = new CommonDialog(dialogId, "", "", toActionUrl,commonLang.dialog.referenceTemplate , false,
			true, false, '', true);
	usdAdd.show();
}

// 上移
function MoveUp(remind,content,remind2,content2) {
	if (endCodeEditing()) {
		var row = $("#cbbTabColumnsCodeDataGrid").datagrid('getSelected');
		if (row == null) {
			//commonLang.tip.alert,'提示',commonLang.tip.content23'请高亮选择要上移的记录！'
			$.messager.alert(commonLang.tip.alert,commonLang.tip.content23, 'warning');
			return false;
		}
		var ctype = row.CTYPE;
		if (ctype == "S") {
			//commonLang.tip.alert '提示',commonLang.tip.content24 '系统记录不能进行上移操作！'
			$.messager.alert(commonLang.tip.alert , commonLang.tip.content24, 'warning');
			return false;
		}
		var index = $("#cbbTabColumnsCodeDataGrid")
				.datagrid('getRowIndex', row);
		mysort(index, 'up', 'cbbTabColumnsCodeDataGrid');
	}
}
// 下移
function MoveDown(remind,content,remind2,content2) {
	if (endCodeEditing()) {
		var row = $("#cbbTabColumnsCodeDataGrid").datagrid('getSelected');
		if (row == null) {
			//commonLang.tip.alert '提示',commonLang.tip.content24'请高亮选择要下移的记录！'
			$.messager.alert(commonLang.tip.alert, commonLang.tip.content25, 'warning');
			return false;
		}
		var ctype = row.CTYPE;
		if (ctype == "S") {
			//commonLang.tip.alert '提示',commonLang.tip.content26'系统记录不能进行下移操作！'
			$.messager.alert(commonLang.tip.alert , commonLang.tip.content26, 'warning');
			return false;
		}
		var index = $("#cbbTabColumnsCodeDataGrid")
				.datagrid('getRowIndex', row);
		mysort(index, 'down', 'cbbTabColumnsCodeDataGrid');
	}
}

// 上移下移的具体方法
function mysort(index, type, gridname) {
	if ("up" == type) {
		if (index != 0) {
			var toup = $('#' + gridname).datagrid('getData').rows[index];
			var upRow = toup.CODE_ORDER; // 选择行排序号
			var todown = $('#' + gridname).datagrid('getData').rows[index - 1];
			var downRow = todown.CODE_ORDER; // 目标行排序号
			// 判断是否为系统记录，如果是，那么只改变自建的顺序值
			var ctype = todown.CTYPE;
			if (ctype == "S") {
				//commonLang.tip.alert '提示'    commonLang.tip.content24 '上移的目标行为【系统】记录，不能进行上移操作！'
				$.messager.alert(commonLang.tip.alert, commonLang.tip.content24, 'warning');
			} else {
				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'endEdit', index);
				$('#' + gridname).datagrid('getData').rows[index] = todown;
				$('#' + gridname).datagrid('getData').rows[index - 1] = toup;

				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'beginEdit', index);
				var uped = $('#' + gridname).datagrid('getEditor', {
					index : index,
					field : 'CODE_ORDER'
				});
				$(uped.target).numberbox('setValue', upRow);
				$('#' + gridname).datagrid('selectRow', index - 1).datagrid(
						'beginEdit', index - 1);
				var doed = $('#' + gridname).datagrid('getEditor', {
					index : (index - 1),
					field : 'CODE_ORDER'
				});
				$(doed.target).numberbox('setValue', downRow);

				$('#' + gridname).datagrid('selectRow', index - 1).datagrid(
						'endEdit', index - 1);
				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'endEdit', index);
				$('#' + gridname).datagrid('selectRow', index - 1);
				$('#' + gridname).datagrid('uncheckRow', index);
			}
		}
	} else if ("down" == type) {
		var rows = $('#' + gridname).datagrid('getRows').length;
		if (index != rows - 1) {
			var todown = $('#' + gridname).datagrid('getData').rows[index];
			var downRow = todown.CODE_ORDER; // 选择行排序号
			var toup = $('#' + gridname).datagrid('getData').rows[index + 1];
			var upRow = toup.CODE_ORDER; // 目标行排序号
			// 判断是否为系统记录，如果是，那么只改变自建的顺序值
			var ctype = toup.CTYPE;
			if (ctype == "S") {
				//commonLang.tip.alert '提示'    commonLang.tip.content26'下移的目标行为【系统】记录，不能进行下移操作！'

				$.messager.alert(commonLang.tip.alert, commonLang.tip.content26, 'warning');
			} else {
				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'endEdit', index);
				$('#' + gridname).datagrid('getData').rows[index + 1] = todown;
				$('#' + gridname).datagrid('getData').rows[index] = toup;

				$('#' + gridname).datagrid('selectRow', index + 1).datagrid(
						'beginEdit', index + 1);
				var uped = $('#' + gridname).datagrid('getEditor', {
					index : (index + 1),
					field : 'CODE_ORDER'
				});
				$(uped.target).numberbox('setValue', upRow);
				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'beginEdit', index);
				var doed = $('#' + gridname).datagrid('getEditor', {
					index : index,
					field : 'CODE_ORDER'
				});
				$(doed.target).numberbox('setValue', downRow);

				$('#' + gridname).datagrid('selectRow', index + 1).datagrid(
						'endEdit', index + 1);
				$('#' + gridname).datagrid('selectRow', index).datagrid(
						'endEdit', index);
				$('#' + gridname).datagrid('selectRow', index + 1);
				$('#' + gridname).datagrid('uncheckRow', index);
			}
		}
	}
}
/**
 * 主表点击行事件
 */
function onClickRowType(rowIndex, field, value) {
	// 刷新子表
	var cid = $('#cbbTabColumnsTypeDataGrid').datagrid("getSelected").id;
	var colName = $('#cbbTabColumnsTypeDataGrid').datagrid("getSelected").colName;
	// 密级字段不能修改通用代码
	/*if (colName == "SECRET_LEVEL") {
		$('#add').linkbutton('disable');
		$('#selectCode').linkbutton('disable');
		$('#removeit').linkbutton('disable');
		$('#MoveUp').linkbutton('disable');
		$('#MoveDown').linkbutton('disable');
		$('#save').linkbutton('disable');
		$('#inputCode').linkbutton('disable');
		$('#exportMoudle').linkbutton('disable');
	} else {*/
		$('#add').linkbutton('enable');
		$('#selectCode').linkbutton('enable');
		$('#removeit').linkbutton('enable');
		$('#MoveUp').linkbutton('enable');
		$('#MoveDown').linkbutton('enable');
		$('#save').linkbutton('enable');
		$('#inputCode').linkbutton('enable');
		$('#exportMoudle').linkbutton('enable');
	/*}*/

	reloadDataGridByCid(cid);
	// 设置编辑行
	if (endTypeEditing()) {
		if (editTypeIndex != rowIndex) {
			$('#cbbTabColumnsTypeDataGrid').datagrid('selectRow', rowIndex)
					.datagrid('beginEdit', rowIndex);
			editTypeIndex = rowIndex;
			// 设置为只读
			var editors = $('#cbbTabColumnsTypeDataGrid').datagrid(
					'getEditors', editTypeIndex);
			var sfgzEditor4 = editors[2];
			var $input = sfgzEditor4.target; // 得到文本框对象
			$input.prop('readonly', true); // 设值只读
		} else {
			$('#cbbTabColumnsTypeDataGrid')
					.datagrid('selectRow', editTypeIndex);
		}
	}
}

/**
 * 子表点击行事件
 */
function onClickRowCode(rowIndex, field, value) {
	if (endCodeEditing()) {
		// 判断是否为系统数据
		var ctype = $('#cbbTabColumnsCodeDataGrid').datagrid('getSelected').CTYPE;
		if (ctype != "S") {
			// 设置编辑行
			if (editCodeIndex != rowIndex) {
				$('#cbbTabColumnsCodeDataGrid').datagrid('selectRow', rowIndex)
						.datagrid('beginEdit', rowIndex);
				editCodeIndex = rowIndex;
			}
		}
	} else {
		$('#cbbTabColumnsCodeDataGrid').datagrid('selectRow', editCodeIndex);
	}
}

// 设置初始化页面的主TABLE第一行选中
function setInitFirstData(data) {
	var rows = $('#cbbTabColumnsTypeDataGrid').datagrid('getRows');
	if (rows.length != 0) {
		$('#cbbTabColumnsTypeDataGrid').datagrid('selectRow', 0);
		var cid = $('#cbbTabColumnsTypeDataGrid').datagrid('getSelected').id;
		reloadDataGridByCid(cid);
	} else {
		reloadDataGridByCid("@@");
	}

}
/**
 * 根据主表ID刷新子表表格数据
 */
function reloadDataGridByCid(cid) {
	var url = "platform/aos/commtablemanagerController/getCommTabColCodeData.json?cid="
			+ cid + "&sysId=" + sysId + "&tableName=" + tableName;
	$('#cbbTabColumnsCodeDataGrid').datagrid("options").url = url;
	$('#cbbTabColumnsCodeDataGrid').datagrid('load', {
		param : null
	});
}

// 选择系统通用代码
function selectCode() {
	var row = $('#cbbTabColumnsTypeDataGrid').datagrid('getSelections');
	if (row.length == 1) {
		var fid = row[0].id;
		var dialogId = "wcodeAddDialog";
		var toActionUrl = "platform/aos/commtablemanagerController/toCommTempletScodeAdd?dialogId="
				+ dialogId
				+ "&sysId="
				+ sysId
				+ "&fid="
				+ fid
				+ "&tableName="
				+ tableName;
		//commonLang.dialog.select "选择"
		var usdAdd = new CommonDialog(dialogId, "800", "300", toActionUrl,
				commonLang.dialog.select, false, true, false, "", true);
		usdAdd.show();
	}
}

/**
 * 导出结构模版
 */
function exportMoudle() {
	var url = baseurl
			+ 'platform/aos/commtablemanagerController/colCodeExportExcelMoudle';
	window.open(url);
}
/**
 * 导入对话框
 */
function openImportDialog() {
	var cid = $('#cbbTabColumnsTypeDataGrid').datagrid("getSelected").id;
	var dialogId = "FormImportDialog";
	var toActionUrl = 'avicit/cbb/techclass/tabledefine/commtablemanager/table_col_code_import.jsp?sysId='
			+ sysId
			+ '&tableName='
			+ tableName
			+ '&nodeId='
			+ nodeId
			+ '&nodeName=' + nodeName + '&cid=' + cid + '&dialogId=' + dialogId;
	//commonLang.dialog.imp 导入
	var usdImport = new CommonDialog(dialogId, "530", "220", toActionUrl, commonLang.dialog.imp,
			false, true, false);
	usdImport.show();
}

function selectAllCol() {
	if (isTemplet == 'Y') { // 显示基本字段
		isTemplet = 'N';
		document.getElementById("selectAllCol").style.display = '';
		document.getElementById("selectCol").style.display = 'none';

	} else { // 显示所有字段
		isTemplet = 'Y';
		document.getElementById("selectAllCol").style.display = 'none';
		document.getElementById("selectCol").style.display = '';

	}
	var url = 'platform/aos/commtablemanagerController/getCbbTabColumnsData.json?sysId='
			+ sysId + '&tableName=' + tableName + '&isTemplet=' + isTemplet;
	$('#cbbTabColumnsTypeDataGrid').datagrid("options").url = url;
	$("#cbbTabColumnsTypeDataGrid").datagrid('load', {
		param : null
	});
}

function fomaterColOrder(value, row, index) {
	if (value == null || value == "null") {
		value = "";
	}
	if (row.colIsDisplay == "N" && row.colIsSys == "Y") {
		return "<font color='red'>" + value + "</font>";
	} else {
		return value;
	}
}

function fomaterColLabel(value, row, index) {
	if (value == null || value == "null") {
		value = "";
	}
	if (row.colIsDisplay == "N" && row.colIsSys == "Y") {
		return "<font color='red'>" + value + "</font>";
	} else {
		return value;
	}
}

function fomaterColRuleTitle(value, row, index) {
	if (value == null || value == "null") {
		value = "";
	}
	if (row.colIsDisplay == "N" && row.colIsSys == "Y") {
		return "<font color='red'>" + value + "</font>";
	} else {
		return value;
	}
}

/**
 * 生成方式下拉选择事件
 * 
 * @param record
 */
function onSelectCom(record) {
	var row = $("#cbbTabColumnsTypeDataGrid").datagrid('getSelected');
	var index = $("#cbbTabColumnsTypeDataGrid").datagrid('getRowIndex', row);
	var editors = $('#cbbTabColumnsTypeDataGrid').datagrid('getEditors', index);
	var sfgzEditor0 = editors[0]; // 类型editor
	var sfgzEditor3 = editors[1];
	var sfgzEditor4 = editors[2];
	var sfgzEditor5 = editors[3];
	// 旧配置选项
	var colDropdownType = $('#cbbTabColumnsTypeDataGrid').datagrid(
			"getSelected").colDropdownType;
	// 新配置选项
	var colDropdownTypeNew = record.lookupCode;
	var colType = row.colType; // 字段类型
	var colRuleName = row.colRuleName; // 生成规则英文
	var colGeneMethod = row.colGeneMethod; // 生成方式

	colDropdownTypeOld = colDropdownType;
	colRuleNameOld = record.colRuleName;
	colRuleTitleOld = record.colRuleTitle;
	customPathOld = record.customPath;

	// integer，float，date类型数据只能配置为【空】
	if ('integer' == colType || 'float' == colType || 'date' == colType) {
		var colTypeName = '';
		if ('integer' == colType) {
			colTypeName = commonLang.dataType.integer;//'整型';
		} else if ('float' == colType) {
			colTypeName = commonLang.dataType.float;//'浮点型';
		} else if ('date' == colType) {
			colTypeName =commonLang.dataType.date;// '日期时间型';
		}
		var colDropDownTypeNewName = '';
		if ('0' == colDropdownTypeNew) {
			colDropDownTypeNewName = commonLang.fomaterType.value0;//'无';
		} else if ('1' == colDropdownTypeNew) {
			colDropDownTypeNewName = commonLang.fomaterType.value1;//'参选';
		} else if ('2' == colDropdownTypeNew) {
			colDropDownTypeNewName = commonLang.fomaterType.value2;//'只选';
		} else if ('3' == colDropdownTypeNew) {
			colDropDownTypeNewName = commonLang.fomaterType.value3;//'选择';
		}
		if ('0' != colDropdownTypeNew) { // 类型不为空，提示
			$.messager.show({
				title :commonLang.tip.alert,// '提示', commonLang.tip.content16 '字段不能配置为'
				msg : colTypeName +commonLang.tip.content16   + '【' + colDropDownTypeNewName
						+ '】'
			});
			// 置为【无】
			sfgzEditor0.target.combobox('setValue', '0');
			return false;
		}
	}
	if (colDropdownTypeNew == colDropdownType && "1" == colGeneMethod) { // 改变后的类型和之前绑定的类型相同
		// 如果为选择，则不能改变选择类型
		if (JSON.stringify(record.lookupCode) == '"3"') {
			var dialogId = "formShowDialog";
			var toActionUrl = "platform/cbb/billDefineManagerController/toRuleShow?dialogId="
					+ dialogId
					+ "&sysId="
					+ sysId
					+ "&selCodeOld="
					+ colRuleName;
			var usdAdd = new CommonDialog(dialogId, "800", "400", toActionUrl,
					//commonLang.dialog.generationModeSelection "生成方式选择"
					commonLang.dialog.generationModeSelection, false, true, false);
			usdAdd.show();
		} else {
			sfgzEditor3.target.val(null);
			sfgzEditor4.target.val(null);
			sfgzEditor5.target.val(null);
		}
	} else {
		if ("0" == colGeneMethod) { // 【生成方式】为空
			// 任意类型可以更改
			if (JSON.stringify(record.lookupCode) == '"3"') {
				var dialogId = "formShowDialog";
				var toActionUrl = "platform/cbb/billDefineManagerController/toRuleShow?dialogId="
						+ dialogId + "&sysId=" + sysId;
				var usdAdd = new CommonDialog(dialogId, "800", "400",
						//commonLang.dialog.generationModeSelection "生成方式选择"
						toActionUrl, commonLang.dialog.generationModeSelection, false, true, false);
				usdAdd.show();
			} else {
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			}
		} else if ("1" == colGeneMethod) { // 【生成方式】为默认值
			if ("0" == colDropdownTypeNew || "1" == colDropdownTypeNew) { // 类型为无或参选
				// 可以更改
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			} else {
				// 不可以更改
				//commonLang.tip.alert '提示'   commonLang.tip.content27'该字段已经配置了【生成方式】为‘默认值’，【类型】只能更改为‘无’或‘参选’！'

				$.messager.alert(commonLang.tip.alert,
						 commonLang.tip.content27, 'warning');
				sfgzEditor0.target.combobox('setValue', colDropdownType);
			}
		} else if ("2" == colGeneMethod) { // 【生成方式】为序列
			// 类型为空时可以更改
			if ("0" == colDropdownTypeNew) {
				// 可以更改
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			} else {
				// 不可以更改
				//commonLang.tip.alert '提示'   commonLang.tip.content28 '该字段已经配置了【生成方式】为‘序列’，【类型】只能更改为‘无’！'
				$.messager.alert(commonLang.tip.alert ,commonLang.tip.content28,
						'warning');
				sfgzEditor0.target.combobox('setValue', colDropdownType);
			}
		} else if ("3" == colGeneMethod) { // 【生成方式】为顺带
			// 任意类型都可以更改
			if (JSON.stringify(record.lookupCode) == '"3"') {
				var dialogId = "formShowDialog";
				var toActionUrl = "platform/cbb/billDefineManagerController/toRuleShow?dialogId="
						+ dialogId + "&sysId=" + sysId;
				var usdAdd = new CommonDialog(dialogId, "800", "400",
						//commonLang.dialog.generationModeSelection "生成方式选择"
						toActionUrl, commonLang.dialog.generationModeSelection, false, true, false);
				usdAdd.show();
			} else {
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			}
		} else if ("4" == colGeneMethod) { // 【生成方式】为组合项
			// 类型为空或参选可更改
			if ("0" == colDropdownTypeNew || "1" == colDropdownTypeNew) {
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			} else {
				//commonLang.tip.alert '提示'   commonLang.tip.content29 ''该字段已经配置了【生成方式】为‘组合项’，【类型】只能更改为‘无’或‘参选’！'
				$.messager.alert(commonLang.tip.alert,
						 commonLang.tip.content29 , 'warning');
				sfgzEditor0.target.combobox('setValue', colDropdownType);
			}
		} else if ("5" == colGeneMethod) { // 【生成方式】为统计生成
			if ("0" == colDropdownTypeNew) {
				sfgzEditor3.target.val(null);
				sfgzEditor4.target.val(null);
				sfgzEditor5.target.val(null);
			} else {
				//commonLang.tip.alert '提示'   commonLang.tip.content30 '该字段已经配置了【生成方式】为‘统计生成’，【类型】只能更改为‘无’！'

				$.messager.alert(commonLang.tip.alert, commonLang.tip.content30,
						'warning');
				sfgzEditor0.target.combobox('setValue', colDropdownType);
			}
		}
	}

	/*
	 * //改变了类型配置 if (colDropdownType != colDropdownTypeNew) { $.messager
	 * .confirm( '请确认', '修改该字段的类型会清除该字段的生成方式配置信息？', function(b) {// 更改配置 if (b) {
	 * if (JSON.stringify(record.lookupCode) == '"3"') { var dialogId =
	 * "formShowDialog"; var toActionUrl =
	 * "platform/cbb/billDefineManagerController/toRuleShow?dialogId=" +
	 * dialogId + "&sysId=" + sysId; var usdAdd = new CommonDialog(dialogId,
	 * "800", "400", toActionUrl, "生成方式选择", false, true, false); usdAdd.show(); }
	 * else { sfgzEditor3.target.val(null); sfgzEditor4.target.val(null);
	 * sfgzEditor5.target.val(null); } //
	 * 清除旧配置信息（COL_GENE_METHOD--0；COL_GENE_METHOD_RULE--""） } else {// 取消
	 * sfgzEditor0.target.combobox('setValue', colDropdownType); } }); }
	 */
}

/**
 * 生成方式选择完成后回填值
 * 
 * @param selCode
 * @param selName
 * @param selUrl
 */
function endSelectCom(selCode, selName, selUrl) {
	var row = $("#cbbTabColumnsTypeDataGrid").datagrid('getSelected');
	var index = $("#cbbTabColumnsTypeDataGrid").datagrid('getRowIndex', row);
	var editors = $('#cbbTabColumnsTypeDataGrid').datagrid('getEditors', index);
	var sfgzEditor3 = editors[1];
	sfgzEditor3.target.val(selCode);
	if (selCode == "custom") {
		var sfgzEditor5 = editors[3];
		sfgzEditor5.target.val(selUrl);
	}
	var sfgzEditor4 = editors[2];
	sfgzEditor4.target.val(selName);
	var $input = sfgzEditor4.target; // 得到文本框对象
	$input.prop('readonly', true); // 设值只读
}

/**
 * 转换【生成方式】
 * 
 * @param value
 * @param row
 * @param index
 * @returns
 */
function fomaterColGeneMethod(value, row, index) {
	var type = "";
	if (value == '0') {
		type =commonLang.fomaterType.empty;// "空";
	} else if (value == '1') {
		type =commonLang.fomaterType.defaultValue;// "默认值";
	} else if (value == '2') {
		type =commonLang.fomaterType.sequence;// "序列";
	} else if (value == '3') {
		type = commonLang.fomaterType.smooth;//"顺带";
	} else if (value == '4') {
		type = commonLang.fomaterType.combinatorialItem;//"组合项";
	} else if (value == '5') {
		type = commonLang.fomaterType.statisticalGeneration;//"统计生成";
	} else if (value == '6') {
		type = commonLang.fomaterType.value3;//"选择";
	}
	if (row.colIsDisplay == "N" && row.colIsSys == "Y") {
		return "<font color='red'>" + type + "</font>";
	} else {
		return type;
	}
}
/*
* 关闭语言选择对话框
*/
function closeL(id){
	$("#chooseL").dialog('close');
};

//打开语言选择
function openLanguageForm(datagrid,type){
	var rows = $("#"+datagrid).datagrid('getChecked');
	if(rows.length !== 1){
		//commonLang.tip.alert5 "请选择一条数据！"
		alert(commonLang.tip.alert5);
		return false;
	}
	var id="";
	if(type=="1"){
		id=rows[0].id;
	}else{
		id=rows[0].ID;
	}
//commonLang.dialog.i18nLanguageSet 多语言设置
	this.cData = new CommonDialog("chooseL","700","400",'platform/aos/commtablemanagerController/chooseLanguage/'+id+"/"+type,commonLang.dialog.i18nLanguageSet,false,true,false);

	this.cData.show();
};
